package com.itheima.d08_change_param;

import java.util.Arrays;

/**
 * 目标：了解可变参数
 */
public class Test {

    /*
        定义方法：接收任意个整型数据
     */                       //int[]  a
    public  static  void  test(int ...  a ){
        //注意：一个形参列表中可变参数只能有一个
        //注意：可变参数必须放在最后

        //System.out.println(a.length);
        //System.out.println(Arrays.toString(a));

        int sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }

        System.out.println("sum="+sum);

    }



    public static void main(String[] args) {
        test();
        test(1);
        test(1,2);
        test(1,2,3);
        test(1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6);
    }

}
